package sql;

import java.sql.SQLException;

import bean.BookBean;

public class RegisterBookInDb {
	DataAccess dataAccess = new DataAccess();
	BookBean bookBean;
	
	public RegisterBookInDb(BookBean bookBean) {
		this.bookBean = bookBean;
	}
	
	public void save() throws ClassNotFoundException, SQLException {
		String insertStatement = "INSERT INTO BOOK (ISBN, TITLE, AUTHOR_FIRST_NAME, "
			+ "AUTHOR_LAST_NAME, PUBLISHER, COPYRIGHT, NUM_OF_PAGES, EDITION, "
			+ "DESCRIPTION, BOOK_CONDITION_CODE, BOOK_CATEGORY_CODE, PRICE, "
			+ "IS_SOLD, SELLER_ID) VALUES ('"
			+ bookBean.getIsbn() + "', '"
			+ bookBean.getTitle().replaceAll("'", "''") + "', '"
			+ bookBean.getAuthorFirstName() + "', '"
			+ bookBean.getAuthorLastName().replaceAll("'", "''") + "', '"
			+ bookBean.getPublisher().replaceAll("'", "''") + "', "
			+ bookBean.getCopyright() + ", "
			+ bookBean.getNumOfPages() + ", '"
			+ bookBean.getEdition() + "', '"
			+ bookBean.getDescription().replaceAll("'", "''") + "', '"
			+ bookBean.getBookConditionCode() + "', '"
			+ bookBean.getBookCategoryCode() + "', "
			+ bookBean.getPrice() + ", '"
			+ bookBean.getIsSold() + "', "
			+ bookBean.getSellerId() + ")";

		dataAccess.modifyTable(insertStatement);
	}
}
